import {request} from "@/http/axios"
import {timeFormats} from "../project/projectType/projectTypeApi.js"
import * as XLSX from "xlsx";

export function getCommentsList(data) {
    return request({
        url: '/comments/list',
        method: "post",
        data
    })
}
export function deleteComment(ids) {
    return request({
        url: '/comments?ids='+ids,
        method: 'delete',
    })
}

// 根据用户名查询项目id
export function getProjectIdByUsername(username) {
    return request({
        url: '/progress/username?username='+username,
        method: 'get',
    })
}

export function exportCommentsExcel(data) {
    let tableData = [
        ['序号', "项目ID", "评论方姓名", "被评论方姓名", "评论内容", "点赞数", "评论时间"]//导出表头
    ] // 表格表头
    data.forEach((item, index) => {
        let rowData = []
        //导出内容的字段
        rowData = [
            index + 1,
            item.projectId,
            item.username,
            item.busername,
            item.content,
            item.support,
            item.createTime,
        ]
        tableData.push(rowData)
    })
    let workSheet = XLSX.utils.aoa_to_sheet(tableData);
    let bookNew = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
    let name = '评论导出数据' + timeFormats() + '.xlsx'
    XLSX.writeFile(bookNew, name) // 保存的文件名
}
